import React from 'react';

import BaseModelNew from './BaseModelNew';
import Config from '../config';

export default class ActivtiyModel extends BaseModelNew {
    constructor() {
      super();
      this.sendRequestList = this.sendRequestList.bind(this);
      this.sendRequestEntryList = this.sendRequestEntryList.bind(this);
      this.sendRequestFollow = this.sendRequestFollow.bind(this);
      this.sendRequestEnter = this.sendRequestEnter.bind(this);
      this.sendRequestContent = this.sendRequestContent.bind(this);
      this.sendRequestBaoming = this.sendRequestBaoming.bind(this);
      this.sendRequestApplicants = this.sendRequestApplicants.bind(this);
      this.sendRequestOneApplicant = this.sendRequestOneApplicant.bind(this);
      this.sendRequestLikeSinger = this.sendRequestLikeSinger.bind(this);
      this.sendCancelEnter = this.sendCancelEnter.bind(this);
      this.sendRequestAuto = this.sendRequestAuto.bind(this);
      this.sendRequestEnterRule = this.sendRequestEnterRule.bind(this);
    }

    //page第几页
    //page_size每页几项
    //tag标签，0包含1，2，3, 6活动，1未开始活动，2进行中活动，3已结束活动, 4热门活动, 5最新活动, 6报名中
    sendRequestList(actionData, callback) {
        //http://118.89.111.124:8080/dqapp/activities?page=1&page_size=5&tag=1
        let home_page = 0;
        if(actionData.home_page != undefined) {
          home_page = actionData.home_page;
        }
        var url = Config.serverUrl + "/activities?page=" + actionData.page + "&page_size=" +
          actionData.page_size + "&tag=" + actionData.tag + "&home_page=" + home_page;
        if(actionData.show_last_days) {
          url += "&show_last_days=" + actionData.show_last_days;
        }
        this.sendGet(url, callback);
    }
    sendRequestEntryList(actionData, callback) {
        //http://118.89.111.124:8080/dqapp/activities?page=1&page_size=5&tag=1
        var url = Config.serverUrl + "/activities/" + actionData.activity_id +'/applicants?' + 
        "page_size=" + actionData.page_size + "&page="+ actionData.page + '&sort_id=' + actionData.sort_id;
        this.sendGet(url, callback);
    }

    //activity_id
    //http://118.89.111.124:8080/dqapp/activities/111
    sendRequestFollow(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activity_id;
      this.sendPut(url, callback)
    }

    //activity_id
    //http://118.89.111.124:8080/dqapp/activities/111/applicants
    sendRequestEnter(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activityData.activity_id + "/applicants";
      var sendData = {
        "avatar_url": data.avatar_url,
        "content": data.content,
        "media_url": data.media_url,
      }
      this.sendPostGetJson(url, JSON.stringify(sendData), callback);
    }
    sendRequestEnterRule(data,callback){
      var url = Config.serverUrl + "/activities/" + data.activity_id+'/applicants/rule';
      this.sendGet(url, callback)
    }
    sendRequestAuto(actionData, callback) {
      var url = Config.serverUrl + "/activities/" + actionData.activity_id + "/applicants";
      var team_id = '';
      var dic ={}
      for(var a in actionData.apply_fields){
        if (a==='1team') {
            team_id=actionData.apply_fields[a];
        }else{
          dic[a]=actionData.apply_fields[a];
        }
      }
      var data = {
        "avatar_url": actionData.avatar_url,
        apply_fields:dic
      }
      if (team_id.length>0) {
        data.apply_Team=team_id;
      }
      this.sendPostGetJson(url, JSON.stringify(data), callback);
    }



    //activity_id
    // http://118.89.111.124:8080/dqapp/activities/1111/applicants
    sendCancelEnter(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activityData.activity_id + "/applicants";
      this.sendDelete(url, {}, callback);
    }

    //activity_id
    //请求内容
    sendRequestContent(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activity_id;
      this.sendGet(url, callback)
    }

    //http://118.89.111.124:8080/dqapp/activities/applied?page=1&page_size=5
    //我的报名
    sendRequestBaoming(data, callback) {
      var url = Config.serverUrl + "/activities/applied?page=" + data.page + "&page_size=" + data.page_size;
      this.sendGet(url, callback);
    }

    //报名列表
    //http://118.89.111.124:8080/dqapp/activities/1123123/applicants?page=1&page_size=5&sort_id=2
    sendRequestApplicants(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activityData.activity_id + "/applicants?page=" + data.page + "&page_size=10&sort_id=2";
      this.sendGet(url, callback);
    }

    //报名者资料
    //http://118.89.111.124:8080/dqapp/activities/12313/applicants/123123
    sendRequestOneApplicant(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activity_id + "/applicants/" + data.applicant_id;
      this.sendGet(url, callback);
    }

    //点赞
    //http://118.89.111.124:8080/dqapp/activities/sofas/applicants/sdfsf
    sendRequestLikeSinger(data, callback) {
      var url = Config.serverUrl + "/activities/" + data.activity_id + "/applicants/" + data.applicant_id;
      this.sendPutNew(url, callback);
    }
}
